{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Welcome to Jupyter!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This repo contains an introduction to [Jupyter](https://jupyter.org) and [IPython](https://ipython.org).\n",
    "\n",
    "Outline of some basics:\n",
    "\n",
    "* [Notebook Basics](../examples/Notebook/Notebook Basics.ipynb)\n",
    "* [IPython - beyond plain python](../examples/IPython Kernel/Beyond Plain Python.ipynb)\n",
    "* [Markdown Cells](../examples/Notebook/Working With Markdown Cells.ipynb)\n",
    "* [Rich Display System](../examples/IPython Kernel/Rich Output.ipynb)\n",
    "* [Custom Display logic](../examples/IPython%20Kernel/Custom%20Display%20Logic.ipynb)\n",
    "* [Running a Secure Public Notebook Server](../examples/Notebook/Running%20the%20Notebook%20Server.ipynb#Securing-the-notebook-server)\n",
    "* [How Jupyter works](../examples/Notebook/Multiple%20Languages%2C%20Frontends.ipynb) to run code in different languages."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also get this tutorial and run it on your laptop:\n",
    "\n",
    "    git clone https://github.com/ipython/ipython-in-depth\n",
    "\n",
    "Install IPython and Jupyter:\n",
    "\n",
    "with [conda](https://www.anaconda.com/download):\n",
    "\n",
    "    conda install ipython jupyter\n",
    "\n",
    "with pip:\n",
    "\n",
    "    # first, always upgrade pip!\n",
    "    pip install --upgrade pip\n",
    "    pip install --upgrade ipython jupyter\n",
    "\n",
    "Start the notebook in the tutorial directory:\n",
    "\n",
    "    cd ipython-in-depth\n",
    "    jupyter notebook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 文本处理\n",
    "## [实验环境](https://jupyter.org/try)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#python之禅,首次import时会展现\n",
    "import this"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "zen = \"\"\"\n",
    "The Zen of Python, by Tim Peters\n",
    "\n",
    "Beautiful is better than ugly.\n",
    "Explicit is better than implicit.\n",
    "Simple is better than complex.\n",
    "Complex is better than complicated.\n",
    "Flat is better than nested.\n",
    "Sparse is better than dense.\n",
    "Readability counts.\n",
    "Special cases aren't special enough to break the rules.\n",
    "Although practicality beats purity.\n",
    "Errors should never pass silently.\n",
    "Unless explicitly silenced.\n",
    "In the face of ambiguity, refuse the temptation to guess.\n",
    "There should be one-- and preferably only one --obvious way to do it.\n",
    "Although that way may not be obvious at first unless you're Dutch.\n",
    "Now is better than never.\n",
    "Although never is often better than *right* now.\n",
    "If the implementation is hard to explain, it's a bad idea.\n",
    "If the implementation is easy to explain, it may be a good idea.\n",
    "Namespaces are one honking great idea -- let's do more of those!\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "word_dict = {}#存储词频\n",
    "for word in zen.split():\n",
    "    #print(word)\n",
    "    word_dict[word] = word_dict.get(word, 0) + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"The\": 1, \"Zen\": 1, \"of\": 3, \"Python,\": 1, \"by\": 1, \"Tim\": 1, \"Peters\": 1, \"Beautiful\": 1, \"is\": 10, \"better\": 8, \"than\": 8, \"ugly.\": 1, \"Explicit\": 1, \"implicit.\": 1, \"Simple\": 1, \"complex.\": 1, \"Complex\": 1, \"complicated.\": 1, \"Flat\": 1, \"nested.\": 1, \"Sparse\": 1, \"dense.\": 1, \"Readability\": 1, \"counts.\": 1, \"Special\": 1, \"cases\": 1, \"aren't\": 1, \"special\": 1, \"enough\": 1, \"to\": 5, \"break\": 1, \"the\": 5, \"rules.\": 1, \"Although\": 3, \"practicality\": 1, \"beats\": 1, \"purity.\": 1, \"Errors\": 1, \"should\": 2, \"never\": 2, \"pass\": 1, \"silently.\": 1, \"Unless\": 1, \"explicitly\": 1, \"silenced.\": 1, \"In\": 1, \"face\": 1, \"ambiguity,\": 1, \"refuse\": 1, \"temptation\": 1, \"guess.\": 1, \"There\": 1, \"be\": 3, \"one--\": 1, \"and\": 1, \"preferably\": 1, \"only\": 1, \"one\": 2, \"--obvious\": 1, \"way\": 2, \"do\": 2, \"it.\": 1, \"that\": 1, \"may\": 2, \"not\": 1, \"obvious\": 1, \"at\": 1, \"first\": 1, \"unless\": 1, \"you're\": 1, \"Dutch.\": 1, \"Now\": 1, \"never.\": 1, \"often\": 1, \"*right*\": 1, \"now.\": 1, \"If\": 2, \"implementation\": 2, \"hard\": 1, \"explain,\": 2, \"it's\": 1, \"a\": 2, \"bad\": 1, \"idea.\": 2, \"easy\": 1, \"it\": 1, \"good\": 1, \"Namespaces\": 1, \"are\": 1, \"honking\": 1, \"great\": 1, \"idea\": 1, \"--\": 1, \"let's\": 1, \"more\": 1, \"those!\": 1}\n",
      "词语\t频次\n",
      "The\t1\n",
      "Zen\t1\n",
      "of\t3\n",
      "Python,\t1\n",
      "by\t1\n",
      "Tim\t1\n",
      "Peters\t1\n",
      "Beautiful\t1\n",
      "is\t10\n",
      "better\t8\n",
      "than\t8\n",
      "ugly.\t1\n",
      "Explicit\t1\n",
      "implicit.\t1\n",
      "Simple\t1\n",
      "complex.\t1\n",
      "Complex\t1\n",
      "complicated.\t1\n",
      "Flat\t1\n",
      "nested.\t1\n",
      "Sparse\t1\n",
      "dense.\t1\n",
      "Readability\t1\n",
      "counts.\t1\n",
      "Special\t1\n",
      "cases\t1\n",
      "aren't\t1\n",
      "special\t1\n",
      "enough\t1\n",
      "to\t5\n",
      "break\t1\n",
      "the\t5\n",
      "rules.\t1\n",
      "Although\t3\n",
      "practicality\t1\n",
      "beats\t1\n",
      "purity.\t1\n",
      "Errors\t1\n",
      "should\t2\n",
      "never\t2\n",
      "pass\t1\n",
      "silently.\t1\n",
      "Unless\t1\n",
      "explicitly\t1\n",
      "silenced.\t1\n",
      "In\t1\n",
      "face\t1\n",
      "ambiguity,\t1\n",
      "refuse\t1\n",
      "temptation\t1\n",
      "guess.\t1\n",
      "There\t1\n",
      "be\t3\n",
      "one--\t1\n",
      "and\t1\n",
      "preferably\t1\n",
      "only\t1\n",
      "one\t2\n",
      "--obvious\t1\n",
      "way\t2\n",
      "do\t2\n",
      "it.\t1\n",
      "that\t1\n",
      "may\t2\n",
      "not\t1\n",
      "obvious\t1\n",
      "at\t1\n",
      "first\t1\n",
      "unless\t1\n",
      "you're\t1\n",
      "Dutch.\t1\n",
      "Now\t1\n",
      "never.\t1\n",
      "often\t1\n",
      "*right*\t1\n",
      "now.\t1\n",
      "If\t2\n",
      "implementation\t2\n",
      "hard\t1\n",
      "explain,\t2\n",
      "it's\t1\n",
      "a\t2\n",
      "bad\t1\n",
      "idea.\t2\n",
      "easy\t1\n",
      "it\t1\n",
      "good\t1\n",
      "Namespaces\t1\n",
      "are\t1\n",
      "honking\t1\n",
      "great\t1\n",
      "idea\t1\n",
      "--\t1\n",
      "let's\t1\n",
      "more\t1\n",
      "those!\t1\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "#json串输出\n",
    "print(json.dumps(word_dict))\n",
    "#词语输出\n",
    "print('词语\\t频次')\n",
    "for k in word_dict:\n",
    "    print('%s\\t%s'%(k, word_dict[k]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "word_list = word_dict.items()\n",
    "# 按照频次排序\n",
    "sort_list = sorted(word_list, key=lambda x:x[1], reverse=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting pyecharts\n",
      "  Downloading https://files.pythonhosted.org/packages/1c/a8/45e5f87ee326fbb48d36650ebb705691e4383529be0ab3281a8a8bffca09/pyecharts-0.5.5-py2.py3-none-any.whl (112kB)\n",
      "\u001b[K    100% |████████████████████████████████| 122kB 2.6MB/s ta 0:00:01\n",
      "\u001b[?25hRequirement already satisfied: pillow in /srv/conda/lib/python3.6/site-packages (from pyecharts)\n",
      "Collecting pyecharts-javascripthon==0.0.6 (from pyecharts)\n",
      "  Downloading https://files.pythonhosted.org/packages/6f/68/23644a394341fef4cbcb48a3fa4b2816408a13a1fa3281cf9030b2ac2d67/pyecharts_javascripthon-0.0.6-py2.py3-none-any.whl\n",
      "Collecting jupyter-echarts-pypkg==0.1.1 (from pyecharts)\n",
      "  Downloading https://files.pythonhosted.org/packages/d9/6d/3ab8c03c0b4cbcf6f7c2ce2c8643f91b8e59ed90fdb072ba3a2731658a7f/jupyter-echarts-pypkg-0.1.1.tar.gz (514kB)\n",
      "\u001b[K    100% |████████████████████████████████| 522kB 1.1MB/s ta 0:00:01\n",
      "\u001b[?25hRequirement already satisfied: jinja2 in /srv/conda/lib/python3.6/site-packages (from pyecharts)\n",
      "Collecting lml==0.0.2 (from pyecharts)\n",
      "  Downloading https://files.pythonhosted.org/packages/8a/6f/0eb22694df07072ea467effdbb8e313222a21788ea7914773f59fd2bb857/lml-0.0.2-py2.py3-none-any.whl\n",
      "Collecting future (from pyecharts)\n",
      "  Downloading https://files.pythonhosted.org/packages/00/2b/8d082ddfed935f3608cc61140df6dcbf0edea1bc3ab52fb6c29ae3e81e85/future-0.16.0.tar.gz (824kB)\n",
      "\u001b[K    100% |████████████████████████████████| 829kB 777kB/s eta 0:00:01\n",
      "\u001b[?25hCollecting javascripthon>=0.10; python_version > \"3.4\" (from pyecharts-javascripthon==0.0.6->pyecharts)\n",
      "  Downloading https://files.pythonhosted.org/packages/ea/ef/b46401e181768b3738660f5dc1f7ea0b334ed17fff685a61503d2989e77e/javascripthon-0.10.tar.gz (538kB)\n",
      "\u001b[K    100% |████████████████████████████████| 542kB 1.2MB/s eta 0:00:01\n",
      "\u001b[?25hRequirement already satisfied: pyecharts-jupyter-installer==0.0.3 in /srv/conda/lib/python3.6/site-packages (from jupyter-echarts-pypkg==0.1.1->pyecharts)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in /srv/conda/lib/python3.6/site-packages (from jinja2->pyecharts)\n",
      "Requirement already satisfied: setuptools in /srv/conda/lib/python3.6/site-packages (from javascripthon>=0.10; python_version > \"3.4\"->pyecharts-javascripthon==0.0.6->pyecharts)\n",
      "Collecting dukpy (from javascripthon>=0.10; python_version > \"3.4\"->pyecharts-javascripthon==0.0.6->pyecharts)\n",
      "  Downloading https://files.pythonhosted.org/packages/c0/35/bd9622ca394e205614fbc8959cd2def6f0e13b3fc7f92ebb7cd094db9c16/dukpy-0.2.0-cp36-cp36m-manylinux1_x86_64.whl (2.0MB)\n",
      "\u001b[K    100% |████████████████████████████████| 2.0MB 334kB/s eta 0:00:01\n",
      "\u001b[?25hCollecting macropy3==1.1.0b2 (from javascripthon>=0.10; python_version > \"3.4\"->pyecharts-javascripthon==0.0.6->pyecharts)\n",
      "  Downloading https://files.pythonhosted.org/packages/8c/b7/a61f9d9bd7de80ca51ef362db5bb6434ea21484c907d2a5f396d97b0274c/macropy3-1.1.0b2.tar.gz (44kB)\n",
      "\u001b[K    100% |████████████████████████████████| 51kB 6.4MB/s eta 0:00:01\n",
      "\u001b[?25hBuilding wheels for collected packages: jupyter-echarts-pypkg, future, javascripthon, macropy3\n",
      "  Running setup.py bdist_wheel for jupyter-echarts-pypkg ... \u001b[?25ldone\n",
      "\u001b[?25h  Stored in directory: /home/jovyan/.cache/pip/wheels/89/8a/50/054d67442cc982f8d99931494653eb690e91eacd20463bbef4\n",
      "  Running setup.py bdist_wheel for future ... \u001b[?25ldone\n",
      "\u001b[?25h  Stored in directory: /home/jovyan/.cache/pip/wheels/bf/c9/a3/c538d90ef17cf7823fa51fc701a7a7a910a80f6a405bf15b1a\n",
      "  Running setup.py bdist_wheel for javascripthon ... \u001b[?25ldone\n",
      "\u001b[?25h  Stored in directory: /home/jovyan/.cache/pip/wheels/f0/a0/6e/5cac90791fefe9c2961f9d5b2fc9b71da8b9b2f927f4012918\n",
      "  Running setup.py bdist_wheel for macropy3 ... \u001b[?25ldone\n",
      "\u001b[?25h  Stored in directory: /home/jovyan/.cache/pip/wheels/ef/ea/95/65744a6a720d5b0b57779da564c68a3e1b221ea998542a78b3\n",
      "Successfully built jupyter-echarts-pypkg future javascripthon macropy3\n",
      "Installing collected packages: dukpy, macropy3, javascripthon, pyecharts-javascripthon, lml, jupyter-echarts-pypkg, future, pyecharts\n",
      "Successfully installed dukpy-0.2.0 future-0.16.0 javascripthon-0.10 jupyter-echarts-pypkg-0.1.1 lml-0.0.2 macropy3-1.1.0b2 pyecharts-0.5.5 pyecharts-javascripthon-0.0.6\n",
      "\u001b[33mYou are using pip version 9.0.1, however version 10.0.1 is available.\n",
      "You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install pyecharts\n",
    "#词云可视化\n",
    "!pip install wordcloud"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts': '/nbextensions/echarts/echarts.min', 'wordcloud': '/nbextensions/echarts/echarts-wordcloud.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "    <div id=\"51551b9f213048a38f0f446e117e4faa\" style=\"width:800px;height:400px;\"></div>\n",
       "\n",
       "\n",
       "<script>\n",
       "    require(['echarts', 'wordcloud'], function(echarts) {\n",
       "        \n",
       "var myChart_51551b9f213048a38f0f446e117e4faa = echarts.init(document.getElementById('51551b9f213048a38f0f446e117e4faa'), 'light', {renderer: 'canvas'});\n",
       "\n",
       "var option_51551b9f213048a38f0f446e117e4faa = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u8bcd\\u4e91\\u53ef\\u89c6\\u5316\",\n",
       "            \"left\": \"auto\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 8341415,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"shape\": \"circle\",\n",
       "            \"rotationRange\": [\n",
       "                -90,\n",
       "                90\n",
       "            ],\n",
       "            \"rotationStep\": 66,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                30,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"The\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(21,107,65)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Zen\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(77,50,46)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"of\",\n",
       "                    \"value\": 3,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(160,128,48)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Python,\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(5,142,138)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"by\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(29,156,48)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Tim\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(103,115,155)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Peters\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(19,157,154)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Beautiful\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(150,102,29)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"is\",\n",
       "                    \"value\": 10,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(28,54,68)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"better\",\n",
       "                    \"value\": 8,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(2,65,98)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"than\",\n",
       "                    \"value\": 8,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(39,112,132)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"ugly.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(110,62,78)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Explicit\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(145,68,42)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"implicit.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(51,40,92)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Simple\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(92,160,87)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"complex.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(112,143,156)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Complex\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(22,76,57)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"complicated.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(116,137,40)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Flat\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(117,70,148)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"nested.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(26,17,143)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Sparse\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(43,21,157)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"dense.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(35,142,109)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Readability\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(136,39,18)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"counts.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(149,16,93)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Special\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(106,21,108)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"cases\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(124,57,1)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"aren't\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(132,66,142)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"special\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(74,74,41)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"enough\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(16,128,18)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"to\",\n",
       "                    \"value\": 5,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(62,137,6)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"break\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(12,32,60)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"the\",\n",
       "                    \"value\": 5,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(81,150,73)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"rules.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(17,137,29)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Although\",\n",
       "                    \"value\": 3,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(58,102,17)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"practicality\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(124,50,138)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"beats\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(158,100,34)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"purity.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(96,26,149)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Errors\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(23,133,89)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"should\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(92,91,82)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"never\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(31,99,16)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"pass\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(143,156,29)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"silently.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(114,54,115)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Unless\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(31,89,139)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"explicitly\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(21,20,107)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"silenced.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(106,91,125)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"In\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(143,15,140)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"face\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(145,66,150)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"ambiguity,\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(124,61,131)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"refuse\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(78,30,45)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"temptation\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(142,62,104)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"guess.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(130,73,137)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"There\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(18,43,15)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"be\",\n",
       "                    \"value\": 3,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(133,140,27)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"one--\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(131,137,111)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"and\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(7,10,1)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"preferably\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(83,1,61)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"only\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(19,97,132)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"one\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(61,57,20)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"--obvious\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(20,79,82)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"way\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(31,108,58)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"do\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(122,28,57)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"it.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(7,154,144)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"that\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(132,69,119)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"may\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(64,105,14)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"not\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(106,101,142)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"obvious\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(135,131,120)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"at\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(136,79,151)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"first\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(62,113,100)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"unless\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(17,53,91)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"you're\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(93,104,67)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Dutch.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(37,0,34)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Now\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(34,158,146)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"never.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(45,27,136)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"often\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(135,119,32)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"*right*\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(91,139,35)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"now.\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(57,146,31)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"If\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(85,51,55)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"implementation\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(30,15,105)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"hard\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(45,37,86)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"explain,\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(72,98,60)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"it's\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(117,124,83)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"a\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(157,27,20)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"bad\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(54,24,49)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"idea.\",\n",
       "                    \"value\": 2,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(151,73,76)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"easy\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(124,33,73)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"it\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(93,140,35)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"good\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(53,95,51)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Namespaces\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(121,95,86)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"are\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(2,134,154)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"honking\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(80,43,70)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"great\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(105,12,50)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"idea\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(50,35,154)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"--\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(121,86,86)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"let's\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(10,146,5)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"more\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(10,121,62)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"those!\",\n",
       "                    \"value\": 1,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(13,61,146)\"\n",
       "                        }\n",
       "                    }\n",
       "                }\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_51551b9f213048a38f0f446e117e4faa.setOption(option_51551b9f213048a38f0f446e117e4faa);\n",
       "\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<pyecharts.charts.wordcloud.WordCloud at 0x7fb8c0ac3550>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#词云可视化,参考地址：https://pyecharts.herokuapp.com/\n",
    "#!pip install pyecharts\n",
    "import pyecharts as pe\n",
    "name_list = [i[0] for i in word_list]\n",
    "freq_list = [i[1] for i in word_list]\n",
    "chart = pe.WordCloud('词云可视化')\n",
    "chart.add(\"\", name_list, freq_list, word_size_range=[30, 100], rotate_step=66)\n",
    "chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts': '/nbextensions/echarts/echarts.min', 'wordcloud': '/nbextensions/echarts/echarts-wordcloud.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "    <div id=\"59cef7d5d4c44003a99e8939220cd9f2\" style=\"width:1300px;height:620px;\"></div>\n",
       "\n",
       "\n",
       "<script>\n",
       "    require(['echarts', 'wordcloud'], function(echarts) {\n",
       "        \n",
       "var myChart_59cef7d5d4c44003a99e8939220cd9f2 = echarts.init(document.getElementById('59cef7d5d4c44003a99e8939220cd9f2'), 'light', {renderer: 'canvas'});\n",
       "\n",
       "var option_59cef7d5d4c44003a99e8939220cd9f2 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"left\": \"auto\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 6832844,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"wordCloud\",\n",
       "            \"shape\": \"circle\",\n",
       "            \"rotationRange\": [\n",
       "                -90,\n",
       "                90\n",
       "            ],\n",
       "            \"rotationStep\": 45,\n",
       "            \"girdSize\": 20,\n",
       "            \"sizeRange\": [\n",
       "                20,\n",
       "                100\n",
       "            ],\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"Sam S Club\",\n",
       "                    \"value\": 10000,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(0,45,59)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Macys\",\n",
       "                    \"value\": 6181,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(79,151,38)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Amy Schumer\",\n",
       "                    \"value\": 4386,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(19,76,45)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Jurassic World\",\n",
       "                    \"value\": 4055,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(96,85,10)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Charter Communications\",\n",
       "                    \"value\": 2467,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(4,63,119)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Chick Fil A\",\n",
       "                    \"value\": 2244,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(52,76,85)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Planet Fitness\",\n",
       "                    \"value\": 1898,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(33,57,22)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Pitch Perfect\",\n",
       "                    \"value\": 1484,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(146,85,101)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Express\",\n",
       "                    \"value\": 1112,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(8,14,97)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Home\",\n",
       "                    \"value\": 965,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(139,42,3)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Johnny Depp\",\n",
       "                    \"value\": 847,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(65,43,158)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Lena Dunham\",\n",
       "                    \"value\": 582,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(37,80,153)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Lewis Hamilton\",\n",
       "                    \"value\": 555,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(13,109,119)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"KXAN\",\n",
       "                    \"value\": 550,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(87,7,12)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Mary Ellen Mark\",\n",
       "                    \"value\": 462,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(27,123,43)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Farrah Abraham\",\n",
       "                    \"value\": 366,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(99,85,86)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Rita Ora\",\n",
       "                    \"value\": 360,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(147,73,5)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Serena Williams\",\n",
       "                    \"value\": 282,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(68,102,92)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"NCAA baseball tournament\",\n",
       "                    \"value\": 273,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(132,93,142)\"\n",
       "                        }\n",
       "                    }\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"Point Break\",\n",
       "                    \"value\": 265,\n",
       "                    \"textStyle\": {\n",
       "                        \"normal\": {\n",
       "                            \"color\": \"rgb(17,23,64)\"\n",
       "                        }\n",
       "                    }\n",
       "                }\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_59cef7d5d4c44003a99e8939220cd9f2.setOption(option_59cef7d5d4c44003a99e8939220cd9f2);\n",
       "\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<pyecharts.charts.wordcloud.WordCloud at 0x7fb8c0ac37b8>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import WordCloud\n",
    "#http://100.69.68.41:8090/files/wordcloud.html\n",
    "name = [\n",
    "    'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',\n",
    "    'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',\n",
    "    'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',\n",
    "    'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']\n",
    "value = [\n",
    "    10000, 6181, 4386, 4055, 2467, 2244, 1898, 1484, 1112,\n",
    "    965, 847, 582, 555, 550, 462, 366, 360, 282, 273, 265]\n",
    "wordcloud = WordCloud(width=1300, height=620)\n",
    "wordcloud.add(\"\", name, value, word_size_range=[20, 100])\n",
    "wordcloud.render('wordcloud.html')\n",
    "wordcloud"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import collections as cl\n",
    "new_dict = cl.OrderedDict()\n",
    "for word in zen.split():\n",
    "    #print(word)\n",
    "    new_dict[word] = new_dict.get(word, 0) + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "odict_keys(['The', 'Zen', 'of', 'Python,', 'by', 'Tim', 'Peters', 'Beautiful', 'is', 'better', 'than', 'ugly.', 'Explicit', 'implicit.', 'Simple', 'complex.', 'Complex', 'complicated.', 'Flat', 'nested.', 'Sparse', 'dense.', 'Readability', 'counts.', 'Special', 'cases', \"aren't\", 'special', 'enough', 'to', 'break', 'the', 'rules.', 'Although', 'practicality', 'beats', 'purity.', 'Errors', 'should', 'never', 'pass', 'silently.', 'Unless', 'explicitly', 'silenced.', 'In', 'face', 'ambiguity,', 'refuse', 'temptation', 'guess.', 'There', 'be', 'one--', 'and', 'preferably', 'only', 'one', '--obvious', 'way', 'do', 'it.', 'that', 'may', 'not', 'obvious', 'at', 'first', 'unless', \"you're\", 'Dutch.', 'Now', 'never.', 'often', '*right*', 'now.', 'If', 'implementation', 'hard', 'explain,', \"it's\", 'a', 'bad', 'idea.', 'easy', 'it', 'good', 'Namespaces', 'are', 'honking', 'great', 'idea', '--', \"let's\", 'more', 'those!'])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_dict.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install jieba\n",
    "#!pip install foolnltk\n",
    "#import fool\n",
    "import json\n",
    "import jieba\n",
    "from jieba import analyse\n",
    "\n",
    "text = u\"一个傻子在北京,难受想哭很不开心啊\"\n",
    "text = u'小明硕士毕业于中国科学院计算所，后在日本京都大学深造,我来到北京清华大学堂'\n",
    "#print(json.dumps(fool.cut(text),ensure_ascii=False))\n",
    "# ['一个', '傻子', '在', '北京']\n",
    "#seg_list = jieba.cut(text)\n",
    "seg_list = jieba.lcut(text)\n",
    "#seg_list = jieba.cut(text, cut_all=True)\n",
    "print(\"jieba分词: \" + \"/ \".join(seg_list))  # 精确模式\n",
    "#res = jieba.analyse.TFIDF(text)\n",
    "res = analyse.extract_tags(text)\n",
    "print(u'TF-IDF关键词提取：'+json.dumps(res,ensure_ascii=False))\n",
    "res = analyse.textrank(text)\n",
    "print(u'TextRank关键词提取：'+json.dumps(res,ensure_ascii=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import Graph\n",
    "\n",
    "nodes = [{\"name\": \"结点1\", \"symbolSize\": 10},\n",
    "         {\"name\": \"结点2\", \"symbolSize\": 20},\n",
    "         {\"name\": \"结点3\", \"symbolSize\": 30},\n",
    "         {\"name\": \"结点4\", \"symbolSize\": 40},\n",
    "         {\"name\": \"结点5\", \"symbolSize\": 50},\n",
    "         {\"name\": \"结点6\", \"symbolSize\": 40},\n",
    "         {\"name\": \"结点7\", \"symbolSize\": 30},\n",
    "         {\"name\": \"结点8\", \"symbolSize\": 20}]\n",
    "links = []\n",
    "for i in nodes:\n",
    "    for j in nodes:\n",
    "        links.append({\"source\": i.get('name'), \"target\": j.get('name')})\n",
    "graph = Graph(\"关系图-力引导布局示例\")\n",
    "graph.add(\"\", nodes, links, repulsion=8000)\n",
    "\n",
    "#graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import random\n",
    "from pyecharts import HeatMap\n",
    "\n",
    "x_axis = [\"12a\", \"1a\", \"2a\", \"3a\", \"4a\", \"5a\", \"6a\", \"7a\", \"8a\", \"9a\", \"10a\", \"11a\",\n",
    "          \"12p\", \"1p\", \"2p\", \"3p\", \"4p\", \"5p\", \"6p\", \"7p\", \"8p\", \"9p\", \"10p\", \"11p\"]\n",
    "y_aixs = [\"Saturday\", \"Friday\", \"Thursday\", \"Wednesday\", \"Tuesday\", \"Monday\", \"Sunday\"]\n",
    "data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)]\n",
    "heatmap = HeatMap()\n",
    "heatmap.add(\"热力图直角坐标系\", x_axis, y_aixs, data, is_visualmap=True,\n",
    "            visual_text_color=\"#000\", visual_orient='horizontal')\n",
    "\n",
    "#heatmap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import Kline\n",
    "\n",
    "v1 = [[2320.26, 2320.26, 2287.3, 2362.94], [2300, 2291.3, 2288.26, 2308.38],\n",
    "      [2295.35, 2346.5, 2295.35, 2345.92], [2347.22, 2358.98, 2337.35, 2363.8],\n",
    "      [2360.75, 2382.48, 2347.89, 2383.76], [2383.43, 2385.42, 2371.23, 2391.82],\n",
    "      [2377.41, 2419.02, 2369.57, 2421.15], [2425.92, 2428.15, 2417.58, 2440.38],\n",
    "      [2411, 2433.13, 2403.3, 2437.42], [2432.68, 2334.48, 2427.7, 2441.73],\n",
    "      [2430.69, 2418.53, 2394.22, 2433.89], [2416.62, 2432.4, 2414.4, 2443.03],\n",
    "      [2441.91, 2421.56, 2418.43, 2444.8], [2420.26, 2382.91, 2373.53, 2427.07],\n",
    "      [2383.49, 2397.18, 2370.61, 2397.94], [2378.82, 2325.95, 2309.17, 2378.82],\n",
    "      [2322.94, 2314.16, 2308.76, 2330.88], [2320.62, 2325.82, 2315.01, 2338.78],\n",
    "      [2313.74, 2293.34, 2289.89, 2340.71], [2297.77, 2313.22, 2292.03, 2324.63],\n",
    "      [2322.32, 2365.59, 2308.92, 2366.16], [2364.54, 2359.51, 2330.86, 2369.65],\n",
    "      [2332.08, 2273.4, 2259.25, 2333.54], [2274.81, 2326.31, 2270.1, 2328.14],\n",
    "      [2333.61, 2347.18, 2321.6, 2351.44], [2340.44, 2324.29, 2304.27, 2352.02],\n",
    "      [2326.42, 2318.61, 2314.59, 2333.67], [2314.68, 2310.59, 2296.58, 2320.96],\n",
    "      [2309.16, 2286.6, 2264.83, 2333.29], [2282.17, 2263.97, 2253.25, 2286.33],\n",
    "      [2255.77, 2270.28, 2253.31, 2276.22]]\n",
    "kline = Kline(\"K 线图示例\")\n",
    "kline.add(\"日K\", [\"2017/7/{}\".format(i + 1) for i in range(31)], v1)\n",
    "\n",
    "#kline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import Line3D\n",
    "\n",
    "import math\n",
    "_data = []\n",
    "for t in range(0, 25000):\n",
    "    _t = t / 1000\n",
    "    x = (1 + 0.25 * math.cos(75 * _t)) * math.cos(_t)\n",
    "    y = (1 + 0.25 * math.cos(75 * _t)) * math.sin(_t)\n",
    "    z = _t + 2.0 * math.sin(75 * _t)\n",
    "    _data.append([x, y, z])\n",
    "range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',\n",
    "               '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']\n",
    "line3d = Line3D(\"3D 折线图示例\", width=1200, height=600)\n",
    "line3d.add(\"\", _data, is_visualmap=True, visual_range_color=range_color, visual_range=[0, 30],\n",
    "           is_grid3d_rotate=True, grid3d_rotate_speed=180)\n",
    "\n",
    "#line3d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import Map\n",
    "\n",
    "value = [455, 10, 66, 78]\n",
    "attr = [\"福建\", \"山东\", \"北京\", \"上海\"]\n",
    "map = Map(\"全国地图示例\", width=1200, height=600)\n",
    "map.add(\"\", attr, value, maptype='china')\n",
    "\n",
    "#map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import Parallel\n",
    "\n",
    "schema = [\"data\", \"AQI\", \"PM2.5\", \"PM10\", \"CO\", \"NO2\"]\n",
    "data = [\n",
    "        [1, 91, 45, 125, 0.82, 34],\n",
    "        [2, 65, 27, 78, 0.86, 45,],\n",
    "        [3, 83, 60, 84, 1.09, 73],\n",
    "        [4, 109, 81, 121, 1.28, 68],\n",
    "        [5, 106, 77, 114, 1.07, 55],\n",
    "        [6, 109, 81, 121, 1.28, 68],\n",
    "        [7, 106, 77, 114, 1.07, 55],\n",
    "        [8, 89, 65, 78, 0.86, 51, 26],\n",
    "        [9, 53, 33, 47, 0.64, 50, 17],\n",
    "        [10, 80, 55, 80, 1.01, 75, 24],\n",
    "        [11, 117, 81, 124, 1.03, 45]\n",
    "]\n",
    "parallel = Parallel(\"平行坐标系-默认指示器\")\n",
    "parallel.config(schema) \n",
    "parallel.add(\"parallel\", data, is_random=True)\n",
    "\n",
    "#parallel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from pyecharts import Bar, Line, Scatter, EffectScatter, Grid  \n",
    "\n",
    "attr = [\"衬衫\", \"羊毛衫\", \"雪纺衫\", \"裤子\", \"高跟鞋\", \"袜子\"]\n",
    "v1 = [5, 20, 36, 10, 75, 90]\n",
    "v2 = [10, 25, 8, 60, 20, 80]\n",
    "bar = Bar(\"柱状图示例\", height=720, width=1200, title_pos=\"65%\")\n",
    "bar.add(\"商家A\", attr, v1, is_stack=True)\n",
    "bar.add(\"商家B\", attr, v2, is_stack=True, legend_pos=\"80%\")\n",
    "line = Line(\"折线图示例\")\n",
    "attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']\n",
    "line.add(\"最高气温\", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=[\"max\", \"min\"], mark_line=[\"average\"])\n",
    "line.add(\"最低气温\", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=[\"max\", \"min\"],\n",
    "         mark_line=[\"average\"], legend_pos=\"20%\")\n",
    "v1 = [5, 20, 36, 10, 75, 90]\n",
    "v2 = [10, 25, 8, 60, 20, 80]\n",
    "scatter = Scatter(\"散点图示例\", title_top=\"50%\", title_pos=\"65%\")\n",
    "scatter.add(\"scatter\", v1, v2, legend_top=\"50%\", legend_pos=\"80%\")\n",
    "es = EffectScatter(\"动态散点图示例\", title_top=\"50%\")\n",
    "es.add(\"es\", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6,\n",
    "        legend_top=\"50%\", legend_pos=\"20%\")\n",
    "\n",
    "grid = Grid()\n",
    "grid.add(bar, grid_bottom=\"60%\", grid_left=\"60%\")\n",
    "grid.add(line, grid_bottom=\"60%\", grid_right=\"60%\")\n",
    "grid.add(scatter, grid_top=\"60%\", grid_left=\"60%\")\n",
    "grid.add(es, grid_top=\"60%\", grid_right=\"60%\")\n",
    "\n",
    "#grid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# pandas读取excel数据示例\n",
    "# 【2016-7-30】 参考：十分钟搞定pandas：http://www.cnblogs.com/chaosimple/p/4153083.html\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# 读取数据 D:\\work\\用户建模画像\\家公司挖掘\\code\\warren.xls\n",
    "# 数据格式：time\n",
    "print('start')\n",
    "#df = pd.read_excel('C:\\Users\\warren\\Desktop\\warren.xlsx',index='time')\n",
    "# df = pandas.read_excel(open('your_xls_xlsx_filename','rb'), sheetname='Sheet 1')\n",
    "input_format = ['phone','time','dict_id','buss_type','custom_type','info','call_id']\n",
    "#df = pd.read_csv('/data2/wangqiwen/athena/recommend/ivr/data/raw_tmp_new.txt', sep='\\t')\n",
    "#指定表头，默认分隔符\\t\n",
    "df = pd.read_table('/data2/wangqiwen/athena/recommend/ivr/data/raw_tmp_new.txt',header=None,names=input_format)\n",
    "df.iloc[:,:5]\n",
    "#dir(df)\n",
    "#df.head()\n",
    "#df.index # 行序号\n",
    "#df.columns # 列名\n",
    "#df['lon'],df['lat'],df[:30] # 按照列名读取数据\n",
    "#df.ix[:30,:3] # 使用ix、loc或者iloc(按照下标组合)进行行列双向读取，即切片操作\n",
    "#df.ix[:20,['lon','lat']] # 跨属性组合选取\n",
    "#df.loc[:100,['time','lon','lat']] # 同上\n",
    "#new = df.iloc[:20,[1,2]]\n",
    "#new.describe # 基本统计信息\n",
    "#type(new)\n",
    "#df[df.lon>117] # 按照数值过滤筛选\n",
    "#df[df.time<'2016-07-20']\n",
    "#new.values.tolist() # DataFrame转成list结构\n",
    "#df.sort(columns='time') # 排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'classes' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-20-f9ff30b0c10a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     12\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     13\u001b[0m \u001b[0mfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0max\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubplots\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m8\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m8\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0mtick_marks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mclasses\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     15\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mxticks\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtick_marks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrotation\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m45\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     16\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0myticks\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtick_marks\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mclasses\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'classes' is not defined"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import confusion_matrix\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "y_pred = [0, 2, 1, 3,0,1,1,3,5,0]\n",
    "y_true = [0, 1, 2, 3,2,1,3,3,1,0]\n",
    "#classes = [i for i in range(6)]\n",
    "y_pred = ['a','b','c','c']\n",
    "y_true = ['a','a','c','b']\n",
    "confmat = confusion_matrix(y_true, y_pred)#混淆矩阵\n",
    "cm = confmat.astype('float') / confmat.sum(axis=1)[:, np.newaxis]\n",
    "\n",
    "fig, ax = plt.subplots(figsize=(8,8))\n",
    "tick_marks = np.arange(len(classes))\n",
    "plt.xticks(tick_marks, classes, rotation=45)\n",
    "plt.yticks(tick_marks, classes)\n",
    "#plt.imshow(confmat, interpolation='nearest', cmap=plt.cm.Blues)\n",
    "ax.matshow(cm, cmap=plt.cm.Blues, alpha=0.3)\n",
    "for i in range(confmat.shape[0]):\n",
    "    for j in range(confmat.shape[1]):\n",
    "        ax.text(x=j, y=i, s=confmat[i,j],va='bottom',ha=\"center\",color='green',fontsize=15)\n",
    "        ax.text(x=j, y=i+0.1, s=format(cm[i,j],'.2f'),va='top',ha=\"center\",color='red',fontsize=15)\n",
    "#plt.colorbar()\n",
    "#plt.tight_layout()\n",
    "plt.xlabel('predict')\n",
    "plt.ylabel('actual')\n",
    "plt.title('confusion matrix')\n",
    "plt.show()\n",
    "#from sklearn.metrics import classification_report\n",
    "#target_names = ['class 0', 'class 1', 'class 2','class 3']\n",
    "#print(classification_report(y_true, y_pred, target_names=target_names))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "#[2018-3-29]wangqiwen@didichuxing.com\n",
    "#refers to: http://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html\n",
    "print(__doc__)\n",
    "\n",
    "import itertools\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from sklearn import svm, datasets\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import confusion_matrix\n",
    "\n",
    "def plot_confusion_matrix(cm, classes, normalize=False, title='Confusion matrix', cmap=plt.cm.Blues):\n",
    "    \"\"\"\n",
    "    This function prints and plots the confusion matrix.\n",
    "    Normalization can be applied by setting `normalize=True`.\n",
    "    \"\"\"\n",
    "    if normalize:\n",
    "        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
    "        print(\"Normalized confusion matrix\")\n",
    "    else:\n",
    "        print('Confusion matrix, without normalization')\n",
    "    cm1 = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
    "    print(cm)\n",
    "    plt.imshow(cm, interpolation='nearest', cmap=cmap)\n",
    "    plt.title(title)\n",
    "    plt.colorbar()\n",
    "    tick_marks = np.arange(len(classes))\n",
    "    plt.xticks(tick_marks, classes, rotation=45)\n",
    "    plt.yticks(tick_marks, classes)\n",
    "    fmt = '.2f' if normalize else 'd'\n",
    "    thresh = cm.max() / 2.\n",
    "    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):\n",
    "        plt.text(j, i, format(cm[i, j], fmt), horizontalalignment=\"center\", color=\"white\" if cm[i, j] > thresh else \"black\")\n",
    "        plt.text(j, i+0.1, format(cm1[i, j], '.2f'), horizontalalignment=\"center\", color=\"red\")\n",
    "    plt.tight_layout()\n",
    "    plt.ylabel('True label')\n",
    "    plt.xlabel('Predicted label')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    # import some data to play with\n",
    "    iris = datasets.load_iris()\n",
    "    X = iris.data\n",
    "    y = iris.target\n",
    "    class_names = iris.target_names\n",
    "    # Split the data into a training set and a test set\n",
    "    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)\n",
    "    # Run classifier, using a model that is too regularized (C too low) to see\n",
    "    # the impact on the results\n",
    "    classifier = svm.SVC(kernel='linear', C=0.01)\n",
    "    y_pred = classifier.fit(X_train, y_train).predict(X_test)\n",
    "    # Compute confusion matrix\n",
    "    cnf_matrix = confusion_matrix(y_test, y_pred)\n",
    "    np.set_printoptions(precision=2)\n",
    "    # Plot non-normalized confusion matrix\n",
    "    plt.figure(figsize=(10,12))\n",
    "    #plt.subplot(211)\n",
    "    plot_confusion_matrix(cnf_matrix, classes=class_names, title='Confusion matrix, without normalization')\n",
    "    #Plot normalized confusion matrix\n",
    "    #plt.subplot(212)\n",
    "    #plot_confusion_matrix(cnf_matrix, classes=class_names, normalize=True, title='Normalized confusion matrix')\n",
    "    plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
